import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'

Vue.use(Router)

/* Router Modules */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        name: '首页',
        meta: { title: '文知将知识产权协作平台', affix: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */

export const asyncRoutes = [
  {
    path: '/customer',
    component: Layout,
    redirect: '/customer/list',
    name: '客户管理',
    hidden: false,
    meta: {
      title: '客户管理',
      icon: 'user'
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/customer/create'),
        name: 'CreateCustomer',
        meta: { title: '创建客户' },
        hidden: false
      },
      {
        path: 'list',
        component: () => import('@/views/customer/list'),
        name: 'CustomerList',
        meta: { title: '客户列表' },
        hidden: false
      },
      {
        path: 'edit/:customerId',
        component: () => import('@/views/customer/edit'),
        name: 'EditCustomer',
        meta: { title: '编辑客户', activeMenu: '/customer/create' },
        hidden: true
      }
    ]
  },
  {
    path: '/contract',
    component: Layout,
    name: '合同管理',
    hidden: false,
    meta: {
      title: '合同管理',
      icon: 'list'
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/contract/create'),
        name: 'CreateContract',
        meta: { title: '创建合同' },
        hidden: false
      },
      {
        path: 'list',
        component: () => import('@/views/contract/list'),
        name: 'ContractList',
        meta: { title: '合同列表' },
        hidden: false
      },
      {
        path: 'edit/:contractId',
        component: () => import('@/views/contract/edit'),
        name: 'EditContract',
        meta: { title: '编辑合同', activeMenu: '/contract/create' },
        hidden: true
      }
    ]
  },
  {
    path: '/case',
    name: '案件管理',
    component: Layout,
    hidden: false,
    meta: {
      title: '案件管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'lawsuit/civil',
        name: 'civil',
        component: () => import('@/views/case/lawsuit/civil/index'),
        hidden: false,
        meta: { title: '民事争议' },
        children: [
          {
            path: 'create',
            component: () => import('@/views/case/lawsuit/civil/create'),
            name: 'CreateCivilLawsuit',
            meta: { title: '创建民事争议' },
            hidden: false
          }, {
            path: 'list',
            component: () => import('@/views/case/lawsuit/civil/list'),
            name: 'CivilLawsuitList',
            meta: { title: '民事争议列表' },
            hidden: false
          },
          {
            path: 'edit/:caseId',
            component: () => import('@/views/case/lawsuit/civil/edit'),
            name: 'EditCivilLawsuit',
            meta: { title: '编辑民事争议', activeMenu: '/case/lawsuit/civil/create' },
            hidden: true
          }]
      },
      {
        path: 'lawsuit/criminal',
        name: 'criminal',
        component: () => import('@/views/case/lawsuit/criminal/index'),
        hidden: false,
        meta: { title: '刑事案件' },
        children: [
          {
            path: 'create',
            component: () => import('@/views/case/lawsuit/criminal/create'),
            name: 'CreateCriminalLawsuit',
            meta: { title: '创建刑事案件' },
            hidden: false
          }, {
            path: 'list',
            component: () => import('@/views/case/lawsuit/criminal/list'),
            name: 'CriminalLawsuitList',
            meta: { title: '刑事案件列表' },
            hidden: false
          },
          {
            path: 'edit/:caseId',
            component: () => import('@/views/case/lawsuit/criminal/edit'),
            name: 'EditCriminalLawsuit',
            meta: { title: '编辑刑事案件', activeMenu: '/case/lawsuit/create' },
            hidden: true
          }]
      },
      {
        path: 'no-lawsuit',
        name: '非诉讼案件',
        component: () => import('@/views/case/no-lawsuit'),
        hidden: false,
        meta: { title: '非诉讼案件' },
        children: [
          {
            path: 'create',
            component: () => import('@/views/case/no-lawsuit/create'),
            name: 'CreateNoLawsuit',
            meta: { title: '创建非诉讼案件' },
            hidden: false
          }, {
            path: 'list',
            component: () => import('@/views/case/no-lawsuit/list'),
            name: 'NoLawsuitList',
            meta: { title: '非诉讼案件列表' },
            hidden: false
          },
          {
            path: 'edit/:caseId',
            component: () => import('@/views/case/no-lawsuit/edit'),
            name: 'EditNoLawsuit',
            meta: { title: '编辑非诉讼案件', activeMenu: '/case/no-lawsuit/create' },
            hidden: true
          }]
      }

      // {
      //   path: 'lawsuit/create',
      //   component: () => import('@/views/case/lawsuit/create'),
      //   name: 'CreateLawsuit',
      //   meta: { title: '创建诉讼案件' },
      //   hidden: false
      // },

    ]
  },
  {
    path: '/system',
    component: Layout,
    name: '系统设置',
    alwaysShow: true,
    meta: { title: '系统设置', icon: 'lock' },
    children: [
      {
        path: 'role/list',
        component: () => import('@/views/permission/permission'),
        name: 'RoleManager',
        meta: { title: '角色管理', icon: 'user' }
      }
    ]
  },
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

// asyncRoutes.push()
export default router
